#!/bin/bash

# 需要检查和添加的环境变量
env_vars=(
  "TSLIB_TSDEVICE=/dev/input/touchscreen0"
  "TSLIB_CONFFILE=/etc/ts.conf"
  "TSLIB_PLUGINDIR=/usr/lib/ts"
  "TSLIB_CALIBFILE=/etc/pointercal"
  "TSLIB_CONSOLEDEVICE=none"
  "TSLIB_FBDEVICE=/dev/fb0"
)

# 目标文件
profile_file="/etc/profile"

# 检查并添加环境变量
for var in "${env_vars[@]}"; do
  var_name=$(echo "$var" | cut -d= -f1)
  var_value=$(echo "$var" | cut -d= -f2)

  # 检查该环境变量是否已经存在于 /etc/profile 中
  if ! grep -q "^export $var_name=" "$profile_file"; then
    # 如果不存在，添加到 /etc/profile 中
    echo "export $var_name=$var_value" | tee -a "$profile_file" > /dev/null
    echo "Added $var_name to $profile_file"
  else
    echo "$var_name already exists in $profile_file"
  fi
done

# 安装tslib库的配置文件
cp ../etc/ts.conf /etc/

# 安装tslib库的lib
cp ../lib/libts* /usr/lib/ -a
cp ../lib/ts /usr/lib/ -a


# 提示脚本执行完毕
echo "Script execution completed."